import React from 'react'
import { Menu, Dropdown, message } from 'antd';
import { UserOutlined } from '@ant-design/icons';
import {connect} from "react-redux"
import {loginFail} from "../../action/index"
function DropMenu(props) {
  
  
  let handleMenuClick = (e) => {
    if (e.key == 2) {
      props.loginFail()
      message.info('退出登录');
    }
  }

  const menu = (
    <Menu onClick={handleMenuClick}>
      <Menu.Item key="1" icon={<UserOutlined />}>
        个人中心
    </Menu.Item>
      <Menu.Item key="2" icon={<UserOutlined />}>
        退出登录
    </Menu.Item>
    </Menu>
  );
  
  let username = props.userReducer.userInfo.username
  return (
    <Dropdown.Button overlay={menu}>
      {username}
    </Dropdown.Button>
  )
}


const mapStateToProps=(state)=>{
  return state
}
export default connect(mapStateToProps,{loginFail})(DropMenu)